package com.lagou.client;

import com.lagou.mmclass.ClientScanner;
import com.lagou.mmclass.User;
import com.lagou.mmclass.UserMessage;

import java.io.IOException;
import java.util.Scanner;

public class ClientView {
    /**
     *
     * 合成复用原则
     */
    private ClientInit cic;
    private StuentManagerView smv;
    public ClientView(ClientInit cic,StuentManagerView smv){
        this.cic=cic;
        this.smv=smv;

    }





    public void ClientMainpage() throws IOException, ClassNotFoundException {
        while (true){
            System.out.println("     \n\n\t在线考试系统");
            System.out.println("----------------------------");
            System.out.print("   [1]学员系统");
            System.out.println("  [2]管理员系统");
            System.out.println("   [0]退出系统");
            System.out.println("----------------------------");
//            Scanner input=new Scanner(System.in);
//            int choose=input.nextInt();
            System.out.println("请选择要进行的业务编号:");
            int choose= ClientScanner.getScanner().nextInt();
            switch (choose){
                case 1:
                    System.out.println("正在进入学员系统");
                    break;
                case 2:
                    ClientManageLogin();
                    break;
                case 3:
                    System.out.println("正在退出系统");
                    return;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }
    }

    private void ClientManageLogin() throws IOException, ClassNotFoundException {
        while (true){

            System.out.println("请输入管理员的姓名");
            String username=ClientScanner.getScanner().next();
            System.out.println("请输入管理员的密码");
            String password=ClientScanner.getScanner().next();
            UserMessage tum = new UserMessage("managerCheck", new User(username, password));
            cic.getOos().writeObject(tum);
            System.out.println("客户端发送信息成功");
            tum= (UserMessage) cic.getOis().readObject();
            if("success".equals(tum.getType())){
                System.out.println("登录成功，欢迎使用");
                smv.Manager();

            }else {
                System.out.println("用户名或者密码错误！！！");
            }
        }
    }
}
